package Utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class CalendarDemo {
    public static void main(String[] args) {
        TimeZone tz = TimeZone.getDefault();
        System.out.println("Time zone: " + tz.getDisplayName());
        Locale loc = Locale.getDefault();
        System.out.println("Locale: " + loc.getDisplayName());
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dt = new Date();
        System.out.println(df.format(dt));
        // extract parts
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int[] fields = { Calendar.YEAR, Calendar.MONTH, Calendar.DATE, Calendar.HOUR, Calendar.MINUTE,
                Calendar.SECOND };
        for (int field : fields) {
            System.out.println(cal.get(field));
        }
        // calculate and compare
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(dt);
        cal2.add(Calendar.HOUR, -3);
        System.out.println(cal2.compareTo(cal));
    }
}
